import { axios } from '@/service/service'
import { CreateHiveReq, ListReq } from './types'

export function getAssetsList(
  params: ListReq,
  page: number,
  pageSize: number
): any {
  return axios({
    url: `/assets/tableInfo/listTableInfo/${page}/${pageSize}/`,
    method: 'get',
    params: {
      ...params
    }
  })
}

export function getQueryListData(): any {
  return axios({
    url: '/assets/tableInfo/queryList',
    method: 'get'
  })
}

export function refreshLineageData(): any {
  return axios({
    url: '/lineage/refresh',
    method: 'get'
  })
}

export function createHiveForm(data: CreateHiveReq): any {
  return axios({
    url: '/assets/newTable/createTable',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function getAssetsInfo(id: string | number): any {
  return axios({
    url: `/assets/tableInfo/query/${id}`,
    method: 'get'
  })
}

export function getLineageInfo(
  schemaName: string | number,
  tableName: string | number
): any {
  return axios({
    url: `/lineage/query/${schemaName}.${tableName}`,
    method: 'get'
  })
}

export function getScheduleInfo(tableName: string | number): any {
  return axios({
    url: `/schedule/getSchedelDetailByName/${tableName}`,
    method: 'get'
  })
}

export function createHiveSimulateForm(data: CreateHiveReq): any {
  return axios({
    url: '/assets/newTable/verifyHiveSql',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    transformRequest: (params) => JSON.stringify(params)
  })
}
